#!/usr/bin/env python
import string

class Message():
	def __init__(self, msg):
		if msg != "":
			msg = self.__stringValidate(msg)
		self.msg = msg

	def __keyValidate(self):
		self.msg = self.msg.replace(chr(0), "/%DCN000%/")
		self.msg = self.msg.replace(chr(5), "/%DCN005%/")
		self.msg = self.msg.replace(chr(36), "/%DCN036%/")
		self.msg = self.msg.replace(chr(96), "/%DCN096%/")
		self.msg = self.msg.replace(chr(124), "/%DCN124%/")
		self.msg = self.msg.replace(chr(126), "/%DCN126%/")
	
	def __stringValidate(self, str):
		str = str.replace("&", "&amp;")
		str = str.replace("$", "&#36;")
		str = str.replace("|", "&#124;")
		return str

	def commandAppend(self, append):
		self.msg = self.msg + append

	def commandAppendCheck(self, append):
		append = self.__stringValidate(append)
		self.msg = self.msg + append

	def commandFormat(self, cmd):
			self.msg = "$" + cmd + " " + self.msg + "|"


	def keyFormat(self, cmd):
		self.__keyValidate()
		self.msg = "$" + cmd + " " + self.msg + "|"
	
	def commandPrint(self):
		print (self.msg)

